from django.db import models

# Create your models here.
class cls(models.Model):
    name = models.CharField(max_length=30)
    start = models.DateField()
    progress = models.CharField(max_length=30)
    remark = models.CharField(max_length=100, null=True, blank=True, default='空')

    def __str__(self):
        return self.name

class student(models.Model):
    name = models.CharField(max_length=20)
    clsid = models.ForeignKey(cls,on_delete=models.SET_NULL,null=True)
    sex = models.CharField(max_length=5,null=True,blank=True,default='不明')
    age = models.IntegerField()
    phonenum = models.CharField(max_length=11,unique=True)
    qq = models.CharField(max_length=15,null=True,blank=True,default="空")
    school = models.CharField(max_length=30,null=True,blank=True,default='空')
    homeaddr = models.CharField(max_length=50,null=True,blank=True,default='空')
    addr = models.CharField(max_length=50)
    progress = models.CharField(max_length=50,null=True,blank=True,default='空')
    job = models.CharField(max_length=30,null=True,blank=True,default='未就业')
    remark = models.CharField(max_length=100,null=True,blank=True,default='空')
    class Meta:
        unique_together=(('name','age','sex'),)

    def __str__(self):
        return self.name

class teacher(models.Model):
    name = models.CharField(max_length=20)
    sex = models.CharField(max_length=5, null=True, blank=True, default='不明')
    phonenum = models.CharField(max_length=11)
    classes = models.ManyToManyField(cls)    # 多对多时，要先删除第三张表，再把想要删除的表中的数据删除
    # through='student',through_fields=('group','person') 在models.ManyToManyField（）中可以指定使用自己创建的第三张表，然后关联其中的两项
    class Meta:
        unique_together=(('name','sex','phonenum'),)   # 设置联合唯一，当这三个值都相同时才会报错

    def __str__(self):
        return self.name

class usrid(models.Model):
    identity = models.CharField(max_length=10)

class usrinfo(models.Model):
    usr = models.CharField(max_length=30)
    pwd = models.CharField(max_length=16)
    uid = models.ForeignKey(to=usrid,on_delete=models.CASCADE,null=True,default="1")


class leave(models.Model):
    name = models.ForeignKey(student,on_delete=models.CASCADE)
    starttime = models.DateTimeField()
    endtime = models.DateTimeField()
    reson = models.CharField(max_length=50)

class area(models.Model):
    codeid = models.IntegerField(12)
    parentid = models.IntegerField(12)
    cityName = models.CharField(max_length=180)

    def __str__(self):
        return self.cityName

